package codeine.configuration.directory;

import java.util.HashMap;
import java.util.Map;

import com.google.common.collect.Maps;

public class PeersListJson {
	
	private Map<String, PeerStatusJson> peersMap = Maps.newHashMap();
	
	public void update(PeerStatusJson peerStatus) {
		HashMap<String, PeerStatusJson> newHashMap = Maps.newHashMap(peersMap);
		newHashMap.put(key(peerStatus), peerStatus);
		peersMap = newHashMap;
	}
	private String key(PeerStatusJson peerStatus) {
		return key(peerStatus.host(), peerStatus.install_dir());
	}
	private String key(String host, String install_dir) {
		return host + ":" + install_dir;
	}
	public Map<String, PeerStatusJson> peers() {
		return peersMap;
	}
	public int findPort(String hostname, String install_dir) {
		return peersMap.get(key(hostname, install_dir)).port();
	}
	public void updaAll(Map<String, PeerStatusJson> peersMap) {
		this.peersMap = peersMap;
	}
}
